package lab_10.com.acme.bankapp.domain.bank;

import java.util.ArrayList;

public class Bank {

	static private final int MAX_CLIENTS = 10;
	private Client[] clients = new Client[MAX_CLIENTS]; // just plain array in
														// here (as it was asked
														// in the task)
	private int number = 0; // number of clients
	private ArrayList<ClientRegistrationListener> listeners;

	public Bank(ArrayList<ClientRegistrationListener> listeners) {
		super();
		this.listeners = listeners;
		this.listeners.add(new DebugClientListener());
	}

	public static class EmailNotificationListener implements
			ClientRegistrationListener {
		@Override
		public void onClientAdded(Client c) {
			System.out.format(
					"Notification email for client %1$s %2$s is to be sent.\n",
					c.getClientSalutation(), c.getName());

		}
	}

	public static class PrintClientListener implements
			ClientRegistrationListener {

		@Override
		public void onClientAdded(Client c) {
			c.printAllClientData();

		}

	}

	private static class DebugClientListener implements
			ClientRegistrationListener {

		@Override
		public void onClientAdded(Client c) {
			System.out.format("Print debug info on client %1$s %2$s.\n",
					c.getClientSalutation(), c.getName());

		}

	}

	public Client addClient(Client client) {
		if (number >= MAX_CLIENTS) {
			return null; // maximum number of clients is reached
		}
		clients[number] = client;
		number++;
		for (ClientRegistrationListener listener : listeners) {
			listener.onClientAdded(client);
		}
		return client;
	}

}
